package com.bbc;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.TextView;
import android.widget.Toast;

import com.bbc.fragment.HomeFragment;
import com.bbc.fragment.MessageFragment;
import com.bbc.fragment.MyViewFragment;
import com.bbc.fragment.PersonFragment;
import com.bbc.fragment.QianFragment;
import com.bbc.fragment.TestFragment;
import com.dou361.update.UpdateHelper;
import com.dou361.update.listener.ForceListener;
import com.dou361.update.type.UpdateType;
import com.hjm.bottomtabbar.BottomTabBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static android.view.Window.FEATURE_NO_TITLE;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.bottomTabBar)
    BottomTabBar bottomTabBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        bottomTabBar.init(getSupportFragmentManager())
                .addTabItem("首页", R.drawable.home_on, HomeFragment.class)
                .addTabItem("信息", R.drawable.message_on, MessageFragment.class)
                .addTabItem("签到", R.drawable.qian_on, QianFragment.class)
                .addTabItem("个人", R.drawable.personal_on, PersonFragment.class)
                .addTabItem("我的自定义", R.drawable.home_on, MyViewFragment.class)
                .addTabItem("我的自定义1", R.drawable.personal_on, TestFragment.class);
        bottomTabBar.setAlpha(1);
        UpdateHelper.getInstance()
                .setUpdateType(UpdateType.autoupdate)//自动检查更新
                .setForceListener(new ForceListener() {
                    @Override
                    public void onUserCancel(boolean force) {//强制更新监听，true则退出app
                        Log.v("cbf", "force = " + force);
                        if (force)
                            finish();
                    }
                })
                .check(MainActivity.this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.KEYCODE_HOME) {
            Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

}
